<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getQuery">查询</Button>
			</Form>
		</div>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" ref="table" :data='list' :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>

		<Modal v-model="modal1" title="加权详情" width='55%'>
			<div style="position: absolute;right: 16px;">
				<Button type="primary" size="large" @click="exportData2" :loading="dcShow2">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
			</div>
			<Input type="text" placeholder="手机号码" class="w200 m-r10" v-model.trim="phone" />
			<Button type="primary" v-on:click="getQuery2">查询</Button>
			<Table class="m-t10" stripe :columns="columns1" :data='list1' :loading="loading2"></Table>
			<Page :total="info2" show-elevator :page-size="pageSize2" show-total @on-change="cuctGetQuery2" :current.sync="page2"></Page>
		</Modal>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				loading: true,
				loading2: true,
				dcShow: false,
				dcShow2: false,
				jsonData: [],
				list: [], // 间接分享收益列表数据
				num: '', // 累计间接分享收益
				info: null, // 总条数
				info2: null, // 总条数
				page: 1, // 页数
				page2: 1, // 页数
				pageSize: 20, // 每页多少条
				pageSize2: 10, // 每页多少条
				current: 1,
				state: '0',
				phoneEmail: '',
				downList: [],
				dataValue: ['', ''], // 时间段值
				tradeNum: '', //交易单号
				phone: '',
				modal1: false,
				times: '',
				list1: [],
				columns: [{
						title: '发放日期',
						align: 'center',
						key: 'outTime',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.outTime == null ? '#' : params.row.outTime)
						}
					}, {
						title: '加权总奖池',
						align: 'center',
						key: 'num',
						render: (h, params) => {
							return h('div', params.row.num == null ? '#' : this.Fixed(params.row.num, 4))
						}
					}, {
						title: '收益百分比',
						align: 'center',
						key: 'ratio',
						render: (h, params) => {
							return h('div', params.row.ratio == null ? '#' : params.row.ratio * 100 + '%')
						}
					},
					{
						title: '发放总量',
						align: 'center',
						key: 'numOfFee',
						render: (h, params) => {
							return h('div', params.row.numOfFee == null ? '#' : this.Fixed(params.row.numOfFee, 4))
						}
					},
					{
						title: '周期',
						align: 'center',
						key: 'cycle',
						render: (h, params) => {
							return h('div', params.row.cycle == null ? '#' : params.row.cycle)
						}
					},
					{
						title: '查看详情',
						align: 'center',
						key: 'createTime',
						render: (h, params) => {
							return h(
								'div', {
									style: {
										cursor: 'pointer',
										color: '#2db7f5'
									},
									on: {
										click: () => {
											this.modal1 = true;
											this.times = params.row.outTime;
											this.getQuery2();
										}
									}
								},
								'查看详情'
							)
						}
					}
				],
				columns1: [{
					title: 'uuid',
					align: 'center',
					key: 'uuid',
					render: (h, params) => {
						return h('div', params.row.uuid == null ? '#' : params.row.uuid)
					}
				}, {
					title: '手机号码',
					align: 'center',
					key: 'phone',
					render: (h, params) => {
						return h('div', params.row.phone == null ? '#' : params.row.phone)
					}
				}, {
					title: '数量',
					align: 'center',
					key: 'rewardNum',
					render: (h, params) => {
						return h('div', params.row.rewardNum == null ? '#' : this.Fixed(params.row.rewardNum, 4))
					}
				}],
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery() // 查询业绩奖励
		},
		methods: {
			exportData() {
				this.jsonData = [];
				this.dcShow = true;
				this.axios.post('/admin/statistical/weighting', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.axios.post('/admin/statistical/weighting', this.qs.stringify({
							current: 1, // 当前页【可选，默认1】
							size: res.data.data.total, // 每页记录数【可选，默认20】
							startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
							endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
						})).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].outTime = this.downList[index].outTime == '' ? '#' : this.downList[index].outTime;
									this.downList[index].num = this.downList[index].num == '' ? '#' : this.Fixed(this.downList[index].num, 4);
									this.downList[index].ratio = this.downList[index].ratio == '' ? '#' : this.downList[index].ratio * 100 + '%';
									this.downList[index].numOfFee = this.downList[index].numOfFee == '' ? '#' : this.Fixed(this.downList[index].numOfFee, 4);
									this.downList[index].cycle = this.downList[index].cycle == '' ? '#' : this.downList[index].cycle;
									this.jsonData.push({
										outTime: this.downList[index].outTime,
										num: this.downList[index].num,
										ratio: this.downList[index].ratio,
										numOfFee: this.downList[index].numOfFee,
										cycle: this.downList[index].cycle,
									})
								})
								let str = `发放日期,手续费汇总,收益百分比,发放总量,周期\n`;
								this.downLoad(this.jsonData, str, '加权奖励');
							}
						})
					}
				})
			},
			exportData2() {
				this.jsonData = [];
				this.dcShow2 = true;
				this.axios.post('/admin/statistical/weighting/times', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					times: this.times,
					phone: this.phone,
				})).then(res => {
					if(res.data.code == 200) {
						this.axios.post('/admin/statistical/weighting/times', this.qs.stringify({
							current: 1, // 当前页【可选，默认1】
							size: res.data.data.total, // 每页记录数【可选，默认20】
							times: this.times,
							phone: this.phone,
						})).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].uuid = this.downList[index].uuid == '' ? '#' : this.downList[index].uuid;
									this.downList[index].phone = this.downList[index].phone == '' ? '#' : this.downList[index].phone;
									this.downList[index].rewardNum = this.downList[index].rewardNum === null ? '#' : this.Fixed(this.downList[index].rewardNum, 4);
									this.jsonData.push({
										uuid: this.downList[index].uuid,
										phone: this.downList[index].phone,
										rewardNum: this.downList[index].rewardNum,
									})
								})
								let str = `uuid,手机号码,数量\n`;
								this.downLoad(this.jsonData, str, '加权奖励详情');
								this.dcShow2 = false;
							}
						})
					}
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getQuery() {
				this.loading = true;
				this.axios.post('/admin/statistical/weighting', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			getQuery2() {
				this.loading2 = true;
				this.axios.post('/admin/statistical/weighting/times', this.qs.stringify({
					times: this.times,
					phone: this.phone,
					current: this.page2, // 当前页【可选，默认1】
					size: this.pageSize2, // 每页记录数【可选，默认20】
				})).then((res) => {
					if(res.data.code == 200) {
						this.list1 = res.data.data.records;
						this.info2 = res.data.data.total;
						this.loading2 = false;
					}
				})
			},
			cuctGetQuery(page) { // 分页查询业绩奖励
				this.loading = true;
				this.axios.post('/admin/statistical/awardRelease', this.qs.stringify({
					current: page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.tradeNum,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			cuctGetQuery2(page) { // 分页查询业绩奖励
				this.loading2 = true;
				this.axios.post('/admin/statistical/weighting/times', this.qs.stringify({
					times: this.times,
					phone: this.phone,
					current: page, // 当前页【可选，默认1】
					size: this.pageSize2, // 每页记录数【可选，默认20】
				})).then((res) => {
					if(res.data.code == 200) {
						this.list1 = res.data.data.records;
						this.info2 = res.data.data.total;
						this.loading2 = false;
					}
				})
			},
		}
	}
</script>